package com.songcha.library_business.proxy.database

import com.songcha.library_business.proxy.userinfo.UserInfoManager
import com.songcha.library_database_douyue.bean.BookLastReadDBBean
import com.songcha.library_database_douyue.greendao.BookLastReadDBBeanDao
import com.songcha.library_database_douyue.manager.GreenDaoManager

class BookLastReadDaoManager {
    companion object{

        @JvmStatic
        fun saveLastReadBook(bookId: String){
            val dao=GreenDaoManager.getInstance().bookLastReadDBBeanDao
            val bean=BookLastReadDBBean().apply {
                this.bookId=bookId
                userId=UserInfoManager.userId
            }
            dao.insertOrReplace(bean)
        }

        @JvmStatic
        fun getLastReadBookId():String{
            val dao=GreenDaoManager.getInstance().bookLastReadDBBeanDao
            val qb=dao.queryBuilder().where(BookLastReadDBBeanDao.Properties.UserId.eq(UserInfoManager.userId))
            val list=qb.list()
            if(list.size>0){
                return list[0].bookId
            }
            return ""
        }
    }
}